package com.sitechasia.webx.components.xtable.toolbar;

import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.toolbar.AbstractItem;
import org.extremecomponents.table.view.html.toolbar.ToolbarItem;
import org.extremecomponents.util.HtmlBuilder;

public class ResItem extends AbstractItem
    implements ToolbarItem
{

    public ResItem()
    {
    }

    public String getText()
    {
        return text;
    }

    public void setText(String text)
    {
        this.text = text;
    }

    public void disabled(HtmlBuilder html)
    {
        html.span().close().append(getText()).spanEnd();
    }

    public void enabled(HtmlBuilder html, TableModel model)
    {
//    	<td><table border="0" cellpadding="0" cellspacing="0" class="btn_go">
//        <tr>
//          <td class="buttonOffLeft" id="btn1_111"></td>
//          <td class="buttonOffMiddle" id="btn1_112" onblur="btn_change(11)" onMouseOver="btn_change_over(11)" onMouseOut="btn_change_out(11)"> GO</td>
//          <td class="buttonOffRight" id="btn1_113"></td>
//        </tr>
//      </table></td>
        html.td(0).close();
        html.table(1).border("0").cellPadding("0").cellSpacing("0").styleClass("btn_go").close();
        html.tr(2).close();
        html.td(3).styleClass("buttonOffLeft").id("btn1_111").close().tdEnd();
        html.td(3).onclick(getAction()).styleClass("buttonOffMiddle").id("btn1_112").append("onblur=\"btn_change(11)\"").onmouseover("btn_change_over(11)").onmouseout("btn_change_out(11)").close();

//        html.append("<td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"btn_go\"><tr>");
//        html.append("<td class=\"buttonOffLeft\" id=\"btn1_111\"></td>");
//        html.append("<td class=\"buttonOffMiddle\" id=\"btn1_112\" onblur=\"btn_change(11)\" onMouseOver=\"btn_change_over(11)\" onMouseOut=\"btn_change_out(11)\"> GO</td>");

        boolean showTooltips = model.getTableHandler().getTable().isShowTooltips();
        if(showTooltips)
        {
            html.span().title(getTooltip());
            html.styleClass(getStyleClass()).style(getStyle());
            html.onmouseover(getOnmouseover()).onmouseout(getOnmouseout());
            html.close();
            html.append(getText());
            html.spanEnd();
        } else
        {
            html.span();
            html.styleClass(getStyleClass()).style(getStyle());
            html.onmouseover(getOnmouseover()).onmouseout(getOnmouseout());
            html.close();
            html.append(getText());
            html.spanEnd();
        }
        html.tdEnd();
        html.td(3).styleClass("buttonOffRight").id("btn1_113").close().tdEnd();
        html.trEnd(2);
        html.tableEnd(1);
        html.tdEnd();

//        html.append("<td class=\"buttonOffRight\" id=\"btn1_113\"></td>");
//        html.append("</tr></table></td>");
    }

    private String text;
}
